<template>
  <BasicTable
    @register="registerTable"
    :rowSelection="rowSelection"
    @change="changeTable"
  >
  </BasicTable>
</template>
<script lang="ts" name="sign-list" setup>
import { ref } from "vue";
import { BasicTable, TableAction } from "/@/components/Table";
import { useDrawer } from "/@/components/Drawer";
import { useMessage } from "/@/hooks/web/useMessage";
import { columns, searchFormSchema } from "./index.data";
import { list } from "./index.api";
import { useListPage } from "/@/hooks/system/useListPage";
import { useSuccess } from "/@/hooks/rw/handleSuccess";
import { IResultTreeData } from "../../system/dict/dict.type";
const showFooter = ref(true);
const [roleUserDrawer, { openDrawer: openRoleUserDrawer }] = useDrawer();
const [registerDrawer, { openDrawer }] = useDrawer();
const [registerDesc, { openDrawer: openRoleDesc }] = useDrawer();
const { rhandleSuccess } = useSuccess();
const { createConfirm: confirm } = useMessage();

const { prefixCls, tableContext, onImportXls, onExportXls } = useListPage({
  designScope: "role-template",
  tableProps: {
    title: "",
    api: list,
    columns: columns,
    immediate: false,
    size: "small",
    pagination: true,
    showTableSetting: true,
    showIndexColumn: true,
    showActionColumn: false,
    tableSetting: { fullScreen: true },
    formConfig: {
      schemas: searchFormSchema,
      autoAdvancedCol: 4,
      baseColProps: { xs: 24, sm: 12, md: 6, lg: 6, xl: 6, xxl: 6 },
      actionColOptions: { xs: 24, sm: 12, md: 6, lg: 6, xl: 6, xxl: 6 },
    },
    actionColumn: {
      width: 70,
    },
    fetchSetting: {
      // 传给后台的当前页字段
      pageField: "pageIndex",
      // 传给后台的每页显示多少条的字段
      sizeField: "pageSize",
      // 接口返回表格数据的字段
      listField: "entities",
      // 接口返回表格总数的字段
    },
  },
});
const [
  registerTable,
  { reload, setSelectedRowKeys },
  { rowSelection, selectedRowKeys },
] = tableContext;
console.log(tableContext, "tableContext");

function changeTable(pagination, filters, sort) {
  console.log(sort, "e");
}

/**
 * 新增
 */
function handleCreate() {
  showFooter.value = true;
  openDrawer(true, {
    record: {},
    isUpdate: false,
  });
}
/**
 * 编辑
 */
function handleEdit(record: Recordable) {
  showFooter.value = true;
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}
/**
 * 详情
 */
function handleDetail(record) {
  showFooter.value = false;
  openRoleDesc(true, {
    record,
    isUpdate: true,
  });
}
/**
 * 删除事件
 */
async function handleDelete(record) {
  del(record.id).then((res: IResultTreeData) => {
    rhandleSuccess(res, reload);
  });
}
/**
 * 批量删除事件
 */
async function batchHandleDelete() {
  confirm({
    title: "注意",
    content: `确定要删除这些数据吗？删除后不可还原`,
    iconType: "warning",
    onOk: async () => {
      let res = await del(selectedRowKeys.value);
      rhandleSuccess(res, reload);
      setSelectedRowKeys([]);
      selectedRowKeys.value = [];
    },
  });
}
/**
 * 角色用户
 */
function handleUser(record) {
  //onSelectChange(selectedRowKeys)
  openRoleUserDrawer(true, record);
}
</script>
